package edu.biwu.cookie02;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * 创建Cookie，响应给浏览器，使用是默认路径
 * 设置一个Cookie: gender=male,默认路径：/Day07_cookie_session/path01
 *      访问/Day07_cookie_session/path01/getCookie01:携带
 *      访问/Day07_cookie_session/path01/path02/getCookie02:
 *      访问/Day07_cookie_session/getCookie03:不携带
 */
@WebServlet("/path01/setCookie01")
public class SetCookie01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //像浏览器中写入一个gender=male。该cookie使用的默认路径 Day07_cookie_session/path01
        response.addCookie(new Cookie("gender","male"));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
